<?php
class Newsletter
{
    /**
     * @var object Zend DB Adapter
     */
    private $_db;
    //private $_view;
    
    public function __construct()
    {
			$this->_db = Zend_Registry::get('db');
    }    
    
	/*public function setView($view) {
		$this->_view = $view;
	}*/
	
	
    
    public function subscribeUser($email, $lang)
    {
    	$view = new Zend_View();
    	$view->addHelperPath('../library/View/Helper','Lion_View_Helper');

    	$this->_db->query("SET NAMES 'utf8'");
    	
    	$validate_email = $this->_db->fetchRow("
    		SELECT COUNT(nletter_userid) AS ROWCOUNT
    		FROM nletter_users
    		WHERE nletter_email = '" . $email . "' AND lang = '" . $lang . "' ");
    	
    	$rowcount = $validate_email['ROWCOUNT'];
    	
    	if($rowcount == 0) {
    		$sql = $this->_db->exec("
	    		INSERT INTO nletter_users(nletter_email, lang, status)
	    		VALUES('" . $email . "', '" . $lang . "', '1')");
	    	if($sql) {
    			echo $view->translate('%Thank you for subscribing to our newsletter.', 'alerts');
    		}
    	} else {    	
	    	echo $view->translate('%You are already subscribed for our newsletter.', 'alerts');
    	}    	  	
    }
} 
?>